#include <bits/stdc++.h>
#define int long long 
using namespace std;

const int maxn = 2e2 + 10;

int n;
int arr[maxn];
int dp[maxn][maxn];


void solve(){
	cin>>n;
	for (int i=1;i<=n;i++) {
		int a;
		cin>>a;
		arr[i]=arr[i+n]=a;
	}
	
	// 环形 DP
	for (int len=2;len<=n;len++) {
		for (int i=1;i+len-1<=2*n;i++) {
			int j=i+len-1;
			for (int k=i;k<j;k++) {
				dp[i][j] = max(dp[i][j], dp[i][k]+dp[k+1][j]+arr[i]*arr[k+1]*arr[j+1]);
//				cout <<i<<' '<<j<<' '<<arr[i]<<' '<<arr[k+1]<<' '<<arr[j+1]<<'\n';
			}
		}
	}
	
	int ans=0;
	for (int i=1;i<=n;i++) {
		ans = max(ans, dp[i][i+n-1]);
	}
	cout << ans<<'\n';
}

signed main(){
	ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
	solve();
	return 0;
}
